There are three controls in VB that allow you to display the drives, folders and files on the users PC, so that you can create your own open dialog, or explorer, albeit in a Windows 3.1 style... If you want to display the files and folders in a windows 9x style, you can take a look at this example program (http://www.developerfusion.com/show/353/). However, it is very complex!

The Drive Combo box lists all the available drives on the PC. It's properties are almost identical to a Combo Box, except that it has a Drive property, and no Style property. 

To get or set the current drive, use the Drive property:

Drive1.Drive = "C:"

or

Msgbox "The current drive is " & Drive1.Drive

When the current drive has changed, the Change event occurs. Note that when the drive changes, the control does not attempt to access it... so if there is no disk in the drive, it does not matter. (This will not be the case when we use the 3 controls together, and the Folder/Files list boxes attempt to read the disk!)

Again, both the file and folder list boxes have almost identical properties to the listbox. You can get the selected items using the Selected property, and set the selection using the ListIndex property. For more information on these standard listbox properties, click here.

To set the path that the file lists the files from, simply set its Path property. The following code sets the file list box to display files in "C:Program Files"

Files1.Path = "C:Program Files"

To set the current folder for the folder listbox, or to change the drive, you set the Path property, just like the file listbox:

'set the folder to C:Program Files
Dir1.Path = "C:Program Files"
'change to floppy
Dir1.Path = "A:"

However, you would obviously need to make sure there was a floppy in Drive A before switching to it. The next section covers how to use the three controls together, and shows you how to add some error handling code to display a warning if there is no floppy in the drive, rather than your program displaying an error message and quitting!

It is very easy to write simple code to utilise all these three controls. The following code integrates the three. When you change the drive it updates the file and directory list, and when you change the folder it lists the files it contains.

' This event occurs when a new drive is selected
Sub Drive1_Change()
    ' change the folder path to the new drive
    Dir1.Path = Drive1.Drive
    ' change the file path
    File1.Path = Drive1.Drive
End Sub

' This event occurs when a new directory is selected
Sub Dir1_Change()
    ' change the file path
    File1.Path = Dir1.Path
End Sub

As you can see, this requires very little code. However one thing you need to take into account is that sometimes the user will select the floppy drive, forgetting to put in a floppy disk. With the code above, your application would crash. To allow for these events, you need to write a bit more code. The following code does the same above, just does not crash when an invalid drive or folder is selected.

Public OldDrive As String
' This event occurs when a new drive is selected
Sub Drive1_Change()
    ' Trap an error if it occurs
    On Error GoTo driveerr
    ' change the folder path to the new drive
    Dir1.Path = Drive1.Drive
    ' change the file path
    File1.Path = Drive1.Drive
    ' Save the new drive name
    OldDrive = Drive1.Drive
    'Exit procedure, no error has occured
    Exit Sub
driveerr:
    ' error handling procedure
    Select Case Err
        Case 68
            MsgBox "Drive not accessable"
            ' Switch back to the previosu drive
            Drive1.Drive = OldDrive
            Exit Sub
        Case Else
            MsgBox "Unexpected Error." & Err & " : " & Error
            Drive1.Drive = OldDrive
            Exit Sub
    End Select
End Sub

' This event occurs when a new directory is selected
Sub Dir1_Change()
    ' change the file path
    File1.Path = Dir1.Path
End Sub

Private Sub Form_Load()
    ' Save the drive name
    OldDrive = Drive1.Drive
End Sub
